//
// Created by Administrator on 2020/1/7.
//

#include <pthread.h>
#include <cerrno>
#include <sys/socket.h>
#include <cstdio>
#include <endian.h>
#include <linux/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <sys/stat.h>
#include "socket_demo.h"
#include "include/log_utils.h"

void* start_server_async(void* arg){
    AKLog("server async");
    const char *fifo_name = "my_fifo";
    int pipe_fd = -1;
    int data_fd = -1;
    int res = 0;
    const int open_mode = O_WRONLY;
    char buffer[PIPE_BUF+1];
    if(access(fifo_name,F_OK)==-1)
    {
        res = mkfifo(fifo_name,0777);
        if(res!=0)
        {
            AKLogErr("could not create fifo\n");
            return nullptr;
        }
    }
    AKLog("process %d opening fifo O_WRONLY\n",getpid());
    pipe_fd = open(fifo_name,open_mode);
    AKLog("pipe_fd:%d\n",pipe_fd);
    return nullptr;
}

void start_server(){
    pthread_t thread_ptr;
    pthread_create(&thread_ptr, nullptr,start_server_async, nullptr);
}
